package com.m1.tzolkin.model;

import com.m1.tzolkin.model.board.ITZBoard;
import com.m1.tzolkin.model.exceptions.StepMoveException;
import com.m1.tzolkin.model.players.ITZPlayer;
import com.m1.tzolkin.model.technos.Technologies;
import com.m1.tzolkin.model.temples.TempleEnum;
import com.m1.tzolkin.model.wheels.IWheelPosition;
import com.m1.tzolkin.model.wheels.WheelEnum;
import com.m1.tzolkin.model.wheels.WheelPosition;

public enum StartingWealth implements IStartingWealth {
	WEALTH_1(new WheelPosition(WheelEnum.CHICHEN_ITZA, 0),
			new Action() {
				/**
				 * 
				 */
				private static final long serialVersionUID = -2606707132162169834L;

				public void doAction(ITZBoard b, ITZPlayer p) {
					p.addCorn(4);
					p.getWallet().addResource(TZResource.WOOD);
					String[] reslog;
					try {
						b.getBank().takeSkull();
						p.getWallet().addSkull();
						reslog = new String[] {
								p.getName(), "EARN", "4", "CORN", ", ", "1", "WOOD", "AND", "GET", "1", "SKULL"	
						};
					} catch (Exception e) {
						reslog = new String[] {
							p.getName(), "EARN", "4", "CORN", "AND", "1", "WOOD"	
						};
					}
					b.getLog().addSentence(reslog);
				}
			}
	),
	WEALTH_2(new WheelPosition(WheelEnum.CHICHEN_ITZA, 3),
			new Action() {
				/**
				 * 
				 */
				private static final long serialVersionUID = 2359986892909443314L;

				public void doAction(ITZBoard b, ITZPlayer p) {
					p.addCorn(5);
					p.getWallet().addResource(TZResource.STONE);
					b.setTechEvolve(1, false);
					b.upTech(Technologies.THEOLOGY, p);
					b.getLog().addSentence(new String[]{
						p.getName(), "EARN", "5", "CORN", "AND", "1", "ROCK"
					});
				}
			}
	),
	WEALTH_3(new WheelPosition(WheelEnum.YAXCHILAN, 7),
			new Action() {
				/**
				 * 
				 */
				private static final long serialVersionUID = 5090245166143708127L;

				public void doAction(ITZBoard b, ITZPlayer p) {
					p.addCorn(3);
					p.getWallet().addResource(TZResource.STONE, 2)
								.addResource(TZResource.WOOD);
					b.getLog().addSentence(new String[]{
						p.getName(), "EARN", "3", "CORN", ", ", "2", "ROCK", "AND", "1", "WOOD" 	
					});
				}
			}
	),
	WEALTH_4(new WheelPosition(WheelEnum.YAXCHILAN, 3),
			new Action() {
				/**
				 * 
				 */
				private static final long serialVersionUID = 3610690769343553624L;

				public void doAction(ITZBoard b, ITZPlayer p) {
					p.addCorn(2);
					p.getWallet().addResource(TZResource.STONE, 2);
					try {
						b.upTemple(p, TempleEnum.KUKULCAN);
					} catch (StepMoveException e) { /* Rien */ }
					b.getLog().addSentence(new String[]{
						p.getName(), "EARN", "2", "CORN", "AND", "2", "ROCK" 	
					});
				}
			}
	),
	WEALTH_5(new WheelPosition(WheelEnum.TIKAL, 7),
			new Action() {
				/**
				 * 
				 */
				private static final long serialVersionUID = -7445904779016936803L;

				public void doAction(ITZBoard b, ITZPlayer p) {
					p.addCorn(6);
					p.getWallet().addResource(TZResource.WOOD)
								.addResource(TZResource.STONE);
					b.getLog().addSentence(new String[]{
						p.getName(), "EARN", "6", "CORN", ", ", "1", "WOOD", "AND", "1", "ROCK" 	
					});
				}
			}
	),
	WEALTH_6(new WheelPosition(WheelEnum.PALENQUE, 3),
			new Action() {
				/**
				 * 
				 */
				private static final long serialVersionUID = 1860832096788606928L;

				public void doAction(ITZBoard b, ITZPlayer p) {
					p.addCorn(5);
					p.getWallet().addResource(TZResource.GOLD);
					try {
						b.upTemple(p, TempleEnum.QUETZALCOATL);
					} catch (StepMoveException e) { /* Rien */ }
					b.getLog().addSentence(new String[]{
						p.getName(), "EARN", "5", "CORN", "AND", "1", "GOLD" 	
					});
				}
			}
	),
	WEALTH_7(new WheelPosition(WheelEnum.UXMAL, 5),
			new Action() {
				/**
				 * 
				 */
				private static final long serialVersionUID = 1973145082522897937L;

				public void doAction(ITZBoard b, ITZPlayer p) {
					p.addPawn();
					b.getLog().addSentence(new String[]{
						p.getName(), "GET", "1", "WORKER" 	
					});
				}
			}
	),
	WEALTH_8(new WheelPosition(WheelEnum.TIKAL, 3),
			new Action() {
				/**
				 * 
				 */
				private static final long serialVersionUID = -5528362238598465748L;

				public void doAction(ITZBoard b, ITZPlayer p) {
					p.addCorn(6);
					p.getWallet().addResource(TZResource.STONE, 2);
					b.getLog().addSentence(new String[]{
						p.getName(), "EARN", "6", "CORN", "AND", "2", "ROCK" 	
					});
				}
			}
	),
	WEALTH_9(new WheelPosition(WheelEnum.CHICHEN_ITZA, 5),
			new Action() {
				/**
				 * 
				 */
				private static final long serialVersionUID = -7701168652353226191L;

				public void doAction(ITZBoard b, ITZPlayer p) {
					p.addCorn(4);
					p.getWallet().addResource(TZResource.WOOD, 3);
					b.getLog().addSentence(new String[]{
						p.getName(), "EARN", "4", "CORN", "AND", "3", "WOOD" 	
					});
				}
			}
	),
	WEALTH_10(new WheelPosition(WheelEnum.PALENQUE, 7),
			new Action() {
				/**
				 * 
				 */
				private static final long serialVersionUID = -3025342591567008478L;

				public void doAction(ITZBoard b, ITZPlayer p) {
					p.addCorn(9);
					p.getWallet().addResource(TZResource.STONE);
					b.getLog().addSentence(new String[]{
						p.getName(), "EARN", "9", "CORN", "AND", "1", "ROCK" 	
					});
				}
			}
	),
	WEALTH_11(new WheelPosition(WheelEnum.PALENQUE, 5),
			new Action() {
				/**
				 * 
				 */
				private static final long serialVersionUID = -3522730653155331069L;

				public void doAction(ITZBoard b, ITZPlayer p) {
					p.getWallet().addResource(TZResource.STONE)
								.addResource(TZResource.GOLD);
					b.setTechEvolve(1, false);
					b.upTech(Technologies.AGRICULTURE, p);
					b.getLog().addSentence(new String[]{
						p.getName(), "EARN", "1", "ROCK", "AND", "1", "GOLD"
					});
				}
			}
	),
	WEALTH_12(new WheelPosition(WheelEnum.UXMAL, 1),
			new Action() {
				/**
				 * 
				 */
				private static final long serialVersionUID = 2335640451470503459L;

				public void doAction(ITZBoard b, ITZPlayer p) {
					p.addCorn(5);
					p.getWallet().addResource(TZResource.STONE);
					try {
						b.upTemple(p, TempleEnum.CHAAC);
					} catch (StepMoveException e) { /* Rien */ }
					b.getLog().addSentence(new String[] {
						p.getName(), "EARN", "5", "CORN", "AND", "1", "ROCK"
					});
				}
			}
	),
	WEALTH_13(new WheelPosition(WheelEnum.YAXCHILAN, 1),
			new Action() {
				/**
				 * 
				 */
				private static final long serialVersionUID = -2952974389358388102L;

				public void doAction(ITZBoard b, ITZPlayer p) {
					p.getWallet().addResource(TZResource.WOOD);
					b.setTechEvolve(1, false);
					b.upTech(Technologies.RESOURCE_EXTRACTION, p);
					try {
						b.upTemple(p, TempleEnum.KUKULCAN);
					} catch (StepMoveException e) { /* Rien */ }
					b.getLog().addSentence(new String[]{
						p.getName(), "EARN", "1", "WOOD"	
					});
				}
			}
	),
	WEALTH_14(new WheelPosition(WheelEnum.UXMAL, 7),
			new Action() {
				/**
				 * 
				 */
				private static final long serialVersionUID = -5902373946122775712L;

				public void doAction(ITZBoard b, ITZPlayer p) {
					p.addCorn(8);
					p.getWallet().addResource(TZResource.GOLD);
					b.getLog().addSentence(new String[]{
						p.getName(), "EARN", "8", "CORN", "AND", "1", "GOLD" 	
					});
				}
			}
	),
	WEALTH_15(new WheelPosition(WheelEnum.TIKAL, 1),
			new Action() {
				/**
				 * 
				 */
				private static final long serialVersionUID = 5122201846409779627L;

				public void doAction(ITZBoard b, ITZPlayer p) {
					p.addCorn(2);
					b.setTechEvolve(1, false);
					b.upTech(Technologies.ARCHITECTURE, p);
					try {
						b.upTemple(p, TempleEnum.CHAAC);
					} catch (StepMoveException e) { /* Rien */ }
					b.getLog().addSentence(new String[]{
						p.getName(), "EARN", "2", "CORN"
					});
				}
			}
	),
	WEALTH_16(new WheelPosition(WheelEnum.PALENQUE, 1),
			new Action() {
				/**
				 * 
				 */
				private static final long serialVersionUID = 2400156255898760307L;

				public void doAction(ITZBoard b, ITZPlayer p) {
					p.addCorn(3);
					b.setTechEvolve(1, false);
					b.upTech(Technologies.AGRICULTURE, p);
					try {
						b.upTemple(p, TempleEnum.QUETZALCOATL);
					} catch (StepMoveException e) { /* Rien */ }
					b.getLog().addSentence(new String[]{
						p.getName(), "EARN", "3", "CORN"
					});
				}
			}
	),
	WEALTH_17(new WheelPosition(WheelEnum.CHICHEN_ITZA, 10),
			new Action() {
				/**
				 * 
				 */
				private static final long serialVersionUID = 868211837548480745L;

				public void doAction(ITZBoard b, ITZPlayer p) {
					p.addCorn(7);
					p.getWallet().addResource(TZResource.WOOD, 2);
					b.getLog().addSentence(new String[]{
						p.getName(), "EARN", "7", "CORN", "AND", "2", "WOOD" 	
					});
				}
			}
	),
	WEALTH_18(new WheelPosition(WheelEnum.YAXCHILAN, 5),
			new Action() {
				/**
				 * 
				 */
				private static final long serialVersionUID = 7209914016110476021L;

				public void doAction(ITZBoard b, ITZPlayer p) {
					p.addCorn(4);
					p.getWallet().addResource(TZResource.WOOD);
					b.setTechEvolve(1, false);
					b.upTech(Technologies.RESOURCE_EXTRACTION, p);
					b.getLog().addSentence(new String[]{
						p.getName(), "EARN", "4", "CORN", "AND", "1", "WOOD"
					});
				}
			}
	),
	WEALTH_19(new WheelPosition(WheelEnum.CHICHEN_ITZA, 7),
			new Action() {
				/**
				 * 
				 */
				private static final long serialVersionUID = 6964113147053033096L;

				public void doAction(ITZBoard b, ITZPlayer p) {
					p.addCorn(2);
					p.getWallet().addResource(TZResource.WOOD, 2);
					b.setTechEvolve(1, false);
					b.upTech(Technologies.THEOLOGY, p);
					b.getLog().addSentence(new String[]{
						p.getName(), "EARN", "2", "CORN", "AND", "2", "WOOD"
					});
				}
			}
	),
	WEALTH_20(new WheelPosition(WheelEnum.TIKAL, 5),
			new Action() {
				/**
				 * 
				 */
				private static final long serialVersionUID = -4834748262714137261L;

				public void doAction(ITZBoard b, ITZPlayer p) {
					p.addCorn(3);
					p.getWallet().addResource(TZResource.GOLD);
					b.setTechEvolve(1, false);
					b.upTech(Technologies.ARCHITECTURE, p);
					b.getLog().addSentence(new String[]{
						p.getName(), "EARN", "3", "CORN", "AND", "1", "GOLD"
					});
				}
			}
	),
	WEALTH_21(new WheelPosition(WheelEnum.UXMAL, 3),
			new Action() {
				/**
				 * 
				 */
				private static final long serialVersionUID = 5512504733945366714L;

				public void doAction(ITZBoard b, ITZPlayer p) {
					p.addCorn(3);
					p.getWallet().addResource(TZResource.WOOD);
					b.getLog().addSentence(new String[]{
						p.getName(), "EARN", "3", "CORN", "AND", "1", "WOOD" 	
					});
				}
			}, 1
	);
	
	// ATTRIBUTS
	
	private final IWheelPosition position;
	private final IAction action;
	private final int fedWorkers;
	
	// CONSTRUCTEUR
	
	private StartingWealth(IWheelPosition p, IAction a) {
		this(p, a, 0);
	}
	
	private StartingWealth(IWheelPosition p, IAction a, int fed) {
		position = p;
		action = a;
		fedWorkers = fed;
	}
	
	// REQUETES

	@Override
	public String getName() {
		return position.toString();
	}

	@Override
	public IWheelPosition getValue() {
		return position;
	}

	@Override
	public int getFedWorkers() {
		return fedWorkers;
	}
	
	// COMMANDES

	@Override
	public void active(ITZBoard b, ITZPlayer p) {
		try {
			action.doAction(b, p);
		} catch (Exception e) { /* Rien */ }
	}

}
